package com.yidu.hbatsams.service.Impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsams.dao.AtsEmpExpertMapper;
import com.yidu.hbatsams.dao.UserMapper;
import com.yidu.hbatsams.domain.AtsEmpExpert;
import com.yidu.hbatsams.domain.User;
import com.yidu.hbatsams.service.emp.AtsEmpExpertService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.List;

/**
 * 专家管理的Servive实现类
 */
@Service
public class AtsEmpExpertServiceImpl implements AtsEmpExpertService {
    @Resource
    AtsEmpExpertMapper atsEmpExpertMapper;//每个方法都需要使用，设为成员变量
    @Resource
    UserMapper userMapper;

    /**
     *
     * @return
     */
    @Override
    public List<AtsEmpExpert> selectExpert() {
        return atsEmpExpertMapper.selectExpert();
    }

    /**
     * 分页查询全部+模糊查询
     * @param pageNum
     * @param pageSize
     * @param expertName
     * @return
     */
    @Override
    public List<AtsEmpExpert> selectAll(Integer pageNum, Integer pageSize, String expertName,String startTime,String endTime) {
        PageHelper.startPage(pageNum, pageSize);

        List<AtsEmpExpert> ats = atsEmpExpertMapper.selectAll(expertName,startTime,endTime);
        return ats;
    }

    /**
     * 查询总行数
     * @return
     */
    @Override
    public Long count() {
        return atsEmpExpertMapper.count();
    }

    /**
     * 逻辑删除
     * @param expertId
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer expertId) {
        int ats = atsEmpExpertMapper.deleteByPrimaryKey(expertId);
        return ats;
    }

    /**
     * 数据新增
     * @param record
     * @return
     */
    @Override
    public int insertExpert(AtsEmpExpert record ) {

        record.setIsva(1);
        record.setCreatTime(new Date(System.currentTimeMillis()));
        int ats = atsEmpExpertMapper.insertExpert(record);
        return ats;
    }
    @Override
    public int insert(User user){
        int userOne = userMapper.insert(user);
        return userOne;
    }

    /**
     * 根据ID查询
     * @param expertId
     * @return
     */
    @Override
    public AtsEmpExpert selectByPrimaryKey(Integer expertId) {
        AtsEmpExpert ats = atsEmpExpertMapper.selectByPrimaryKey(expertId);
        return ats;
    }

    /**
     * 根据ID进行修改
     * @param record
     * @return
     */
    @Override
    public int updateExpertByPrimaryKey(AtsEmpExpert record ) {

        record.setIsva(1);
        AtsEmpExpert ats = atsEmpExpertMapper.selectByPrimaryKey(record.getExpertId());
        record.setCreatTime(ats.getCreatTime());
        return atsEmpExpertMapper.updateExpertByPrimaryKey(record);
    }

    /**
     * 修改用户表
     * @param user
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(User user){
        //record.setUserValidity("有效");
        return userMapper.updateByPrimaryKeySelective(user);
    }

    /**
     * 查询用户表的主键
     * @param companyId
     * @param clerkId
     * @return
     */
    @Override
    public User findClerk(String companyId, String clerkId){
        return userMapper.findClerk(companyId,clerkId);
    }

    /**
     * 删除用户表信息
     * @param companyId
     * @param clerkId
     * @return
     */
    @Override
    public int deleteClerk(String companyId, String clerkId) {
        return userMapper.deleteClerk(companyId,clerkId);
    }
}
